package com.hqyj.project.controller;

import com.hqyj.project.dto.AttendanceDto;
import com.hqyj.project.service.AttendService;
import com.hqyj.project.service.UserService;
import com.hqyj.project.utils.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
@Slf4j
public class AttendController {
    @Autowired
    private UserService userService;

    @Autowired
    private AttendService attendService;

    @GetMapping("/attendance")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)
    public CommonResult queryAttendance(AttendanceDto attendanceDto){
        return attendService.queryAttendance(attendanceDto);
    }

    @DeleteMapping("/attendance/{clockid}")
//    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)
    public CommonResult removeOneByClockId(@PathVariable("clockid") Integer clockId){
        return attendService.removeOneByClockId(clockId);
    }

    @PutMapping("/attendance")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)
    public CommonResult updateAttendance(@RequestBody AttendanceDto attendanceDto){
        return attendService.updateAttendance(attendanceDto);
    }

    //批量删除
    @DeleteMapping("/attendances/{ids}")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)
    public CommonResult removeAttendances(@PathVariable("ids") Integer[] clockIds){
        return attendService.removeAttendances(clockIds);
    }

    //添加
    @PostMapping("/attendance")
    public CommonResult addAttendance(@RequestBody AttendanceDto attendanceDto){
        return attendService.addAttendance(attendanceDto);
    }

    @PostMapping("/attendanceSelf")
    public CommonResult querySelf(AttendanceDto attendanceDto){
        return attendService.querySelf(attendanceDto);
    }
}
